listitemwidget: Don't look at rubberbanding
authorMatthias Clasen <mclasen@redhat.com>
Sat, 6 Jun 2020 04:23:04 +0000 (00:23 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 6 Jun 2020 04:23:04 +0000 (00:23 -0400)
Move the selection changes to button release, to
avoid conflict with the drag gesture for rubberbanding.
This avoids peeking at the parent, and is generally
nicer.

Among other things, you can now shift-click to select
a range in the colors demo in gtk4-demo.

gtk/gtklistitemwidget.c

index f700269823ba12b5708adaa4485274434c33aa6e..5c57d1b257ef2de68f3f60481f33591e0c7bce19 100644 (file)
@@ -324,8 +324,6 @@ gtk_list_item_widget_click_gesture_pressed (GtkGestureClick   *gesture,
 {
   GtkListItemWidgetPrivate *priv = gtk_list_item_widget_get_instance_private (self);
   GtkWidget *widget = GTK_WIDGET (self);
-  GtkWidget * parent = gtk_widget_get_parent (widget);
-  gboolean rubberband;
 
   if (priv->list_item && !priv->list_item->selectable && !priv->list_item->activatable)
     {
@@ -333,12 +331,33 @@ gtk_list_item_widget_click_gesture_pressed (GtkGestureClick   *gesture,
       return;
     }
 
-  if (GTK_IS_LIST_BASE (parent))
-    rubberband = gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (parent));
-  else
-    rubberband = FALSE;
+  if (!priv->list_item || priv->list_item->activatable)
+    {
+      if (n_press == 2 || priv->single_click_activate)
+        {
+          gtk_widget_activate_action (GTK_WIDGET (self),
+                                      "list.activate-item",
+                                      "u",
+                                      priv->position);
+        }
+    }
 
-  if (!rubberband && (!priv->list_item || priv->list_item->selectable))
+  gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_ACTIVE, FALSE);
+
+  if (gtk_widget_get_focus_on_click (widget))
+    gtk_widget_grab_focus (widget);
+}
+
+static void
+gtk_list_item_widget_click_gesture_released (GtkGestureClick   *gesture,
+                                             int                n_press,
+                                             double             x,
+                                             double             y,
+                                             GtkListItemWidget *self)
+{
+  GtkListItemWidgetPrivate *priv = gtk_list_item_widget_get_instance_private (self);
+
+  if (!priv->list_item || priv->list_item->selectable)
     {
       GdkModifierType state;
       GdkEvent *event;
@@ -356,21 +375,7 @@ gtk_list_item_widget_click_gesture_pressed (GtkGestureClick   *gesture,
                                   priv->position, modify, extend);
     }
 
-  if (!priv->list_item || priv->list_item->activatable)
-    {
-      if (n_press == 2 || priv->single_click_activate)
-        {
-          gtk_widget_activate_action (GTK_WIDGET (self),
-                                      "list.activate-item",
-                                      "u",
-                                      priv->position);
-        }
-    }
-
-  gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_ACTIVE, FALSE);
-
-  if (gtk_widget_get_focus_on_click (widget))
-    gtk_widget_grab_focus (widget);
+  gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_ACTIVE);
 }
 
 static void
@@ -406,16 +411,6 @@ gtk_list_item_widget_hover_cb (GtkEventControllerMotion *controller,
     }
 }
 
-static void
-gtk_list_item_widget_click_gesture_released (GtkGestureClick   *gesture,
-                                             int                n_press,
-                                             double             x,
-                                             double             y,
-                                             GtkListItemWidget *self)
-{
-  gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_ACTIVE);
-}
-
 static void
 gtk_list_item_widget_click_gesture_canceled (GtkGestureClick   *gesture,
                                              GdkEventSequence  *sequence,